package it.tukano.io;

import it.tukano.collections.ListExt;
import java.io.IOException;
import java.io.InputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;

public class ZipReader {
    
    private final FileExt file;
    private ZipFile zipFile;

    /**
     * Instance initializer
     */
    public ZipReader(FileExt file) {
        this.file = file;
    }
    
    public ListExt<? extends ZipEntry> listEntries() throws IOException {
        ZipFile zip = getZipFile();
        return ListExt.newListExt(zip.entries());
    }
    
    public InputStream openEntry(ZipEntry e) throws IOException {
        return getZipFile().getInputStream(e);
    }

    private ZipFile getZipFile() throws IOException {
        if(zipFile == null) {
            zipFile = new ZipFile(file.getFile());
        }
        return zipFile;
    }
}
